package com.fjnldx.mes.service.scheduling;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjnldx.mes.domain.domainReq.*;
import com.fjnldx.mes.domain.domainRes.Result;
import com.fjnldx.mes.domain.domainRes.Results;
import com.fjnldx.mes.domain.enums.DevSnAreaEnum;
import com.fjnldx.mes.domain.enums.GXEnum;
import com.fjnldx.mes.domain.enums.WeekEnum;
import com.fjnldx.mes.domain.pojo.*;
import com.fjnldx.mes.mapper.common.MesContainerMapper;
import com.fjnldx.mes.mapper.productionPlanManagement.ProductionPlanManagementMapper;
import com.fjnldx.mes.mapper.scheduling.*;
import com.fjnldx.mes.mapper.schedulingClasses.SchedulingClassesMapper;
import com.fjnldx.mes.mapper.shiftManagement.SchedulingShiftMapper;
import com.fjnldx.mes.service.shiftManagement.ShiftManageService;
import com.fjnldx.mes.utils.Common;
import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.thymeleaf.util.StringUtils;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;

@Service
@Transactional(rollbackFor = Exception.class)
public class SchedulingService {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
    @Resource
    SchedulingMapper schedulingMapper;
    @Resource
    ProductionPlanManagementMapper productionPlanManagementMapper;
    @Resource
    SchedulingTemplateMapper schedulingTemplateMapper;
    @Resource
    SchedulingShiftMapper schedulingShiftMapper;
    @Resource
    SchedulingPersonnelMapper schedulingPersonnelMapper;
    @Resource
    ShiftManageService shiftManageService;

    @Resource
    MesContainerMapper mesContainerMapper;

    @Resource
    SchedulingClassesMapper schedulingClassesMapper;

    @Resource
    DictionaryDataListMapper dictionaryDataListMapper;
    @Resource
    SpindleNumberMapper spindleNumberMapper;
    @Resource
    SpindleNumberTemplateMapper spindleNumberTemplateMapper;

    @Resource
    Common common;


    /**
     * 一键删除排班
     */
    public Result oneClickDelete(ScheReqParams data) {
        String bc = data.getBc();
        String gongxu = data.getGongxu();
        LocalDate time = data.getTime();
        QueryWrapper<Scheduling> wrapper = new QueryWrapper<>();

        if ("络筒".equals(gongxu)) {
            QueryWrapper<SpindleNumberMapping> spindleNumberMappingQueryWrapper = new QueryWrapper<>();
            spindleNumberMappingQueryWrapper.eq("bc", bc);
            spindleNumberMappingQueryWrapper.apply(String.format("DATEDIFF(time,'%s')=0", time));
            spindleNumberMapper.delete(spindleNumberMappingQueryWrapper);
        }
        if (gongxu.equals("前纺")) {
            ArrayList<String> gx = new ArrayList<>();
            gx.add("细纱");
            gx.add("络筒");
            wrapper.clear();
            wrapper.eq("bc", bc);
            wrapper.notIn("current_gongxu", gx);
        } else {
            wrapper.clear();
            wrapper.eq("bc", bc);
            wrapper.eq("current_gongxu", gongxu);
        }
        wrapper.apply(String.format("DATEDIFF(start_time,'%s')=0", time));
        schedulingMapper.delete(wrapper);
        return Result.success("删除成功");
    }

    /**
     * 复制到排班模板
     */
    public Result copyToSchedulingTemplate(ScheReqParams data) {
        String bc = data.getBc();
        String gongxu = data.getGongxu();
        QueryWrapper<SchedulingTemplate> wrapper = new QueryWrapper<>();
        wrapper.eq("bc", bc);
        wrapper.eq("current_gongxu", gongxu);
        schedulingTemplateMapper.delete(wrapper);
        schedulingTemplateMapper.copyToSchedulingTemplate(data);
        if ("络筒".equals(gongxu)) {
            QueryWrapper<SpindleNumberMappingTemplate> spindleNumberMappingQueryWrapper = new QueryWrapper<>();
            spindleNumberMappingQueryWrapper.eq("bc", bc);
            spindleNumberTemplateMapper.delete(spindleNumberMappingQueryWrapper);
            schedulingTemplateMapper.copyToSchedulingTemplateLt(data);
        }
        return Result.success("复制成功");
    }

    /**
     * 查询级联关系-集团-组织-车间-工序-工种
     */
    public Result addPeopleCascadeRelationship(String keyName) {
        List<Map> res = mesContainerMapper.queryBelong(keyName);
        for (Map item : res) {
            item.put("key_query", item.get("key_name").toString().replaceAll("\\d+", ""));
        }
        return Result.success(res);
    }

    /**
     * 获取班次信息-班长-班教练
     */
    public Result getShiftInformation(SchedulingClassesInfoQuery data) {
        if (data.getOrg() == null || StringUtils.isEmpty(data.getOrg()) || data.getCj() == null || StringUtils.isEmpty(data.getCj()) || data.getGongxu() == null || StringUtils.isEmpty(data.getGongxu()) || data.getTime() == null || data.getBc() == null || StringUtils.isEmpty(data.getBc())) {
            return Result.error("请输入对应组织、车间、工序、日期、班次");
        }
        QueryWrapper<SchedulingClasses> wrapper = new QueryWrapper<>();
        wrapper.eq("org", data.getOrg());
        wrapper.eq("cj", data.getCj());
        wrapper.eq("gongxu", data.getGongxu());
        wrapper.apply(String.format("DATEDIFF(start_time,'%s')=0", data.getTime()));
        wrapper.eq("bc", data.getBc());
        wrapper.last("limit 1");
        SchedulingClasses result = schedulingClassesMapper.selectOne(wrapper);
        return Result.success(result);
    }

    /**
     * 获取工序设备号
     */
    public Result getEquipmentByGx(GongXu params) {
        List<Map<String, Object>> equipmentList = schedulingMapper.getEquipmentByGx(params);
        return Result.success(equipmentList);
    }

    /**
     * 人员管理-集团-级联
     */
    public Result queryPersonnelGroup() throws Exception {
        try {
            List<Group> list = schedulingMapper.queryPersonnelGroup();
            return Result.success(list);
        } catch (Exception e) {
            logger.error(e.getMessage());
            throw new Exception();
        }
    }

    /**
     * 人员管理-集团-组织-级联
     */
    public Result queryPersonnelGroupAndOrg(Group data) throws Exception {
        try {
            List<GroupAndOrg> list = schedulingMapper.queryPersonnelGroupAndOrg(data);
            return Result.success(list);
        } catch (Exception e) {
            logger.error(e.getMessage());
            throw new Exception();
        }
    }


    /**
     * 查询人员排班记录
     */
    public Results queryPersonnelClasses(SchedulingReq data) {
        if (data.getOrg() == null || StringUtils.isEmpty(data.getOrg()) || data.getCj() == null || StringUtils.isEmpty(data.getCj()) || data.getTime() == null || data.getBc() == null || StringUtils.isEmpty(data.getBc()) || data.getCurrent_gongxu() == null || StringUtils.isEmpty(data.getCurrent_gongxu()) || data.getCurrent_work_type() == null || StringUtils.isEmpty(data.getCurrent_work_type())) {
            return Results.error("请输入对应组织、车间、工序、工种、日期、班次");
        }
        List<Map<String, Object>> records = null;
        List<Map<String, Object>> pzs = null;
        List<Object> objects = new ArrayList<>();
        if ("前纺".equals(data.getCurrent_gongxu())) {
            records = mesContainerMapper.querySchedulingQf(data);
            List<Map<String, Object>> maps = mesContainerMapper.queryNoTypeOfWorkInModelQf(data);
            records.addAll(maps);
            pzs = mesContainerMapper.queryPzByGxAndNowQf(data);
        } else if ("细纱".equals(data.getCurrent_gongxu())) {
            records = mesContainerMapper.queryScheduling(data);
            if ("摆管工".equals(data.getCurrent_work_type())) {
                List<Map<String, Object>> maps = mesContainerMapper.queryNoTypeOfWorkInModel(data);
                records.addAll(maps);
            }
            pzs = mesContainerMapper.queryPzByGxAndNow(data);
        }
        if (records == null || pzs == null) {
            return Results.error("无数据");
        }
        // pz总类
        for (Map<String, Object> item : pzs) {
            LinkedHashMap<String, Object> obj = new LinkedHashMap<>();
            obj.put("pz" + item.get("id"), item.get("pz"));
            obj.put("jhkt", item.get("jhkt"));
            obj.put("sjkt", item.get("sjkt"));
            obj.put("sykt", item.get("sykt"));
            objects.add(obj);
        }
        for (Map<String, Object> record : records) {
            List<String> pzArr = new ArrayList<>();
            List<String> devArr = new ArrayList<>();

            if (record.get("pzAndDev") != null) {
                String[] pzAndDev = record.get("pzAndDev").toString().split("==");
                for (String item : pzAndDev) {
                    String[] str = item.split("##");
                    pzArr.add(str[0]);
                    devArr.add(str[1]);
                }
                for (int i = 0; i < pzArr.size(); i++) {
                    String pz = pzArr.get(i);
                    String[] devSnArea = devArr.get(i).split(",");
                    for (Map<String, Object> t_pz : pzs) {
                        if (pz.equals(t_pz.get("pz"))) {
                            record.put("pz" + t_pz.get("id"), Arrays.asList(devSnArea));
                            break;
                        }
                    }
                }
            }

            record.remove("pz");
            record.remove("devSnArea");
            record.remove("devSnArea2");
        }

        DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime signTime = LocalDateTime.of(data.getTime(), LocalTime.of(15, 59, 59));
        List<Map<String, Object>> upData = records.stream().filter(item -> signTime.isAfter(LocalDateTime.parse(String.valueOf(item.get("start_time")).substring(0, String.valueOf(item.get("start_time")).indexOf(".")), timeFormatter))).collect(Collectors.toList());
        List<Map<String, Object>> downData = records.stream().filter(item -> signTime.isBefore(LocalDateTime.parse(String.valueOf(item.get("start_time")).substring(0, String.valueOf(item.get("start_time")).indexOf(".")), timeFormatter))).collect(Collectors.toList());

        return Results.success(upData, objects, downData);
    }

    /**
     * 查询人员排班记录络筒
     */
    public Result queryPersonnelClassesLt(SchedulingReq data) {
        if (StringUtils.isEmpty(data.getOrg()) || StringUtils.isEmpty(data.getCj()) || data.getTime() == null || StringUtils.isEmpty(data.getBc()) || StringUtils.isEmpty(data.getCurrent_gongxu())) {
            return Result.error("请输入对应组织、车间、工序、日期、班次");
        }
        List<Map<String, Object>> records = mesContainerMapper.querySchedulingLt(data);
        for (Map<String, Object> record : records) {
            String[] devSnArea = record.get("devSnArea").toString().split(",");
            record.put("devSnArea", devSnArea);
            Object dsAreaRe = record.get("dsArea");
            List<String> dsArea = new ArrayList<>();
            if (dsAreaRe != null) {
                dsArea = Arrays.asList(record.get("dsArea").toString().split(","));
            }
            record.put("dsArea", dsArea);
        }
        List<Map<String, Object>> maps = mesContainerMapper.queryNoTypeOfWorkInModel(data);
        records.addAll(maps);
        return Result.success(records);
    }

    /**
     * 移除该人员排班
     */
    public Result deletePersonnelClasses(SchedulingReqOfName data) {
        Integer id = data.getId();
        LocalDate time = data.getTime();
        Scheduling s = schedulingMapper.selectById(id);
        String gongxu = s.getCurrent_gongxu();
        String cj = s.getCj();
        String bc = s.getBc();
        String gh = s.getGh();
        LocalDateTime startTime = s.getStart_time();
        LocalDateTime endTime = s.getEnd_time();
        String idLt = s.getIdLt();
        String devSn = s.getDevSn();
        String workType = s.getCurrent_work_type();
        QueryWrapper<Scheduling> wrapper = new QueryWrapper<>();
        Scheduling person = null;
        if ("落纱队员".equals(workType)) {
            // 获取小队
            wrapper.clear();
            wrapper.eq("cj", cj);
            wrapper.eq("current_gongxu", gongxu);
            wrapper.eq("bc", bc);
            wrapper.apply(String.format("DATEDIFF(start_time,'%s')=0", time));
            wrapper.eq("current_work_type", "落纱队员");
            wrapper.eq("gh", gh);
            wrapper.last("limit 1");
            person = schedulingMapper.selectOne(wrapper);
        }
        if (StringUtils.isEmpty(devSn) && gongxu.equals("络筒")) {
            // 无机台人员
            schedulingMapper.deleteById(id);
        } else {
            if ("络筒".equals(gongxu)) {
                // 工序、车间、班次、时间、工号、机台号
                QueryWrapper<SpindleNumberMapping> spindleNumberMapperQueryWrapper = new QueryWrapper<>();
                spindleNumberMapperQueryWrapper.eq("gongxu", gongxu);
                spindleNumberMapperQueryWrapper.eq("cj", cj);
                spindleNumberMapperQueryWrapper.eq("bc", bc);
                spindleNumberMapperQueryWrapper.eq("gh", gh);
                spindleNumberMapperQueryWrapper.eq("idLt", idLt);
                spindleNumberMapperQueryWrapper.eq("devSn", devSn);
                spindleNumberMapperQueryWrapper.apply(String.format("DATEDIFF(time,'%s')=0", time));
                spindleNumberMapper.delete(spindleNumberMapperQueryWrapper);
                QueryWrapper<Scheduling> schedulingQueryWrapper = new QueryWrapper<>();
                schedulingQueryWrapper.eq("current_gongxu", gongxu);
                schedulingQueryWrapper.eq("cj", cj);
                schedulingQueryWrapper.eq("bc", bc);
                schedulingQueryWrapper.eq("gh", gh);
                if (idLt != null) {
                    schedulingQueryWrapper.eq("idLt", idLt);
                } else {
                    schedulingQueryWrapper.isNull("idLt");
                }
                schedulingQueryWrapper.eq("devSn", devSn);
                schedulingQueryWrapper.eq("current_work_type", workType);
                spindleNumberMapperQueryWrapper.apply(String.format("DATEDIFF(start_time,'%s')=0", time));
                schedulingMapper.delete(schedulingQueryWrapper);
            } else {
                mesContainerMapper.deletePersonnelClasses(s);
            }
        }
        /* 落纱队员特殊处理 */
        if ("落纱队员".equals(workType)) {
            // 当前小队落纱队长
            wrapper.clear();
            wrapper.eq("cj", cj);
            wrapper.eq("current_gongxu", gongxu);
            wrapper.eq("bc", bc);
            wrapper.apply(String.format("DATEDIFF(start_time,'%s')=0", time));
            wrapper.eq("current_work_type", "落纱队长");
            wrapper.eq("current_dh", person.getCurrent_dh());
            wrapper.gt("end_time", startTime);
            wrapper.lt("start_time", endTime);
            wrapper.groupBy("gh");
            List<Scheduling> curLsDz = schedulingMapper.selectList(wrapper);
            if (curLsDz.size() > 0) {
                // 当前小队落纱队员
                wrapper.clear();
                wrapper.eq("cj", cj);
                wrapper.eq("current_gongxu", gongxu);
                wrapper.eq("bc", bc);
                wrapper.apply(String.format("DATEDIFF(start_time,'%s')=0", time));
                wrapper.eq("current_work_type", "落纱队员");
                wrapper.ne("devSn", "");
                wrapper.eq("current_dh", person.getCurrent_dh());
                wrapper.gt("end_time", startTime);
                wrapper.lt("start_time", endTime);
                wrapper.groupBy("devSn");
                wrapper.orderByAsc("devSn+0");
                List<Scheduling> curLsDy = schedulingMapper.selectList(wrapper);
                if (curLsDy.size() > 1) {
                    // 删除当前小队落纱队长
                    for (Scheduling item : curLsDz) {
                        wrapper.clear();
                        wrapper.eq("cj", item.getCj());
                        wrapper.eq("current_gongxu", item.getCurrent_gongxu());
                        wrapper.eq("bc", item.getBc());
                        wrapper.apply(String.format("DATEDIFF(start_time,'%s')=0", time));
                        wrapper.eq("gh", item.getGh());
                        wrapper.eq("current_dh", person.getCurrent_dh());
                        wrapper.eq("current_work_type", "落纱队长");
                        wrapper.gt("end_time", startTime);
                        wrapper.lt("start_time", endTime);
                        schedulingMapper.delete(wrapper);
                        for (Scheduling pre : curLsDy) {
                            item.setDevSn(pre.getDevSn());
                            item.setUpdate_time(LocalDateTime.now());
                            schedulingMapper.insert(item);
                        }
                    }
                }

            }
        }
        return Result.success("删除成功");
    }

    /**
     * 更新落纱次数-批量
     */
    public Result updateMesLscsBatch(UpdateLscsReq data) {
        System.out.println("====================");
        System.out.println(data.toString());
        mesContainerMapper.updateMesLscsBatch(data);
        return Result.success("更新成功");
    }

    /**
     * 更新落纱次数-单独-根据机台号
     */
    public Result updateMesLscsSingle(UpdateLscsSingleReq data) {
        switch (data.getFlag()) {
            case "1":
                // 增行
                mesContainerMapper.updateMesLscsSingleChangeDev(data);
                return Result.success("增行成功");
            case "2":
                // 减行
                mesContainerMapper.updateMesLscsSingle(data);
                return Result.success("减行成功");
            case "3":
                // 编辑
                // 先设置为NULL
                mesContainerMapper.updateMesLscsSingle(data);
                mesContainerMapper.updateMesLscsSingleChangeDev(data);
                return Result.success("编辑成功");
            default:
                return Result.error("请输入操作类型flag");
        }
    }

    /**
     * 查询落纱次数
     */
    public Result queryMesLscs(InputChangeReq data) throws InterruptedException {
        HashMap<String, Object> res = new HashMap<>();
        List<Map<String, Object>> batch = mesContainerMapper.queryLscsChangeBatch(data);
        res.put("batch", batch);
        List<Map<String, Object>> single = mesContainerMapper.queryLscsChangeSingle(data);
        res.put("single", single);
        return Result.success(res);
    }

    /**
     * 查询各队换粗纱锭数明细
     */
    public Result queryReplaceInfoCsDs(InputChangeReq data) {
        HashMap<String, Object> res = new HashMap<>();
        List<Map<String, Object>> sum = mesContainerMapper.queryReplaceSumCsDs(data);
        res.put("sum", sum);
        List<Map> result = new ArrayList<>();
        List<Map<String, Object>> details = mesContainerMapper.queryReplaceDetailCsDs(data);
        if (details.size() > 0) {
            for (Map<String, Object> item : details) {
                String[] hcsds = item.get("hcsds").toString().split(",");
                item.put("hcsds", hcsds);

                String devSn = String.valueOf(item.get("devSn"));
                Integer id = Integer.parseInt(String.valueOf(item.get("id")));
                HashMap<String, Object> map = new HashMap<>();
                for (String i : hcsds) {
                    map.put("devSn", devSn);
                    map.put("id", id);
                    map.put("hcsds", i);
                    result.add(map);
                }

            }
        }

        res.put("details", result);
        return Result.success(res);
    }

    /**
     * 换粗纱段数更新
     */
    public Result updateReplaceCsDs(UpdateReplaceCsDsReq data) {
        try {
            switch (data.getFlag()) {
                case "1":
                    Map<String, Object> res = mesContainerMapper.queryHCsDs(data);
                    List<String> hcsdsArray = new ArrayList<>();
                    boolean containsFlag = false;
                    if (res != null && res.get("hcsds") != null) {
                        List<String> list = Arrays.asList(res.get("hcsds").toString().split(","));
                        hcsdsArray = new ArrayList<>(list);
                        containsFlag = hcsdsArray.contains(data.getHcsds());
                    }
                    // 增行
                    if (containsFlag) {
                        return Result.error("请勿给同一机台增加重复段数");
                    }
                    hcsdsArray.add(data.getHcsds());
                    hcsdsArray.removeAll(Collections.singleton(""));
                    data.setHcsdsValue(StringUtils.join(hcsdsArray, ","));
                    mesContainerMapper.updateReplaceCsDsChangeDev(data);
                    return Result.success("增行成功");
                case "2":
                    // 减行
                    Map<String, Object> res2 = mesContainerMapper.queryHCsDs(data);
                    List<String> hcsdsArray2 = new ArrayList<>();
                    boolean containsFlag2 = false;
                    if (res2 != null && res2.get("hcsds") != null) {
                        List<String> list = Arrays.asList(res2.get("hcsds").toString().split(","));
                        hcsdsArray2 = new ArrayList<>(list);
                        containsFlag2 = hcsdsArray2.contains(data.getHcsds());
                    }
                    if (!containsFlag2) {
                        return Result.success("改机台不存在此段数");
                    }
                    hcsdsArray2.remove(data.getHcsds());
                    hcsdsArray2.removeAll(Collections.singleton(""));
                    System.out.println(hcsdsArray2.toString());
                    data.setHcsdsValue(StringUtils.join(hcsdsArray2, ","));
                    mesContainerMapper.updateReplaceCsDsChangeDev(data);
                    return Result.success("减行成功");
                case "3":
                    // 编辑
                    Map<String, Object> map = mesContainerMapper.queryProductionPlanInfoCs(data.getId(), data.getBc());
                    List<String> hcsdsArrayEdit = new ArrayList<>();
                    if (map.get("hcsds") != null) {
                        List<String> listEdit = Arrays.asList(map.get("hcsds").toString().split(","));
                        hcsdsArrayEdit = new ArrayList<>(listEdit);
                    }
                    if (map.get("devSn").equals(data.getDevSn())) {
                        // 编辑段数
                        hcsdsArrayEdit.remove(data.getPre_hcsds());
                        hcsdsArrayEdit.add(data.getHcsds());
                        hcsdsArrayEdit.removeAll(Collections.singleton(""));
                        data.setHcsdsValue(StringUtils.join(hcsdsArrayEdit, ","));
                        mesContainerMapper.updateReplaceCsDs(data);
                        return Result.success("id更新成功");
                    }
                    // 机台号改变
                    List<String> rep = new ArrayList<>();
                    rep.addAll(hcsdsArrayEdit);
                    rep.remove(data.getPre_hcsds());
                    data.setHcsdsValue(StringUtils.join(rep, ","));
                    mesContainerMapper.updateReplaceCsDs(data);
                    boolean contains = hcsdsArrayEdit.contains(data.getHcsds());
                    if (!contains) {
                        hcsdsArrayEdit.add(data.getHcsds());
                    }
                    hcsdsArrayEdit.removeAll(Collections.singleton(""));
                    data.setHcsdsValue(StringUtils.join(hcsdsArrayEdit, ","));
                    mesContainerMapper.updateReplaceCsDsChangeDev(data);
                    return Result.success("编辑成功");
                default:
                    return Result.error("请输入操作类型flag");
            }
        } catch (Exception e) {
            return Result.error("更新失败");
        }

    }

    /**
     * 一键复制昨日某班人员排班
     */
    public Result queryScheduleYesterday(CopyBc data) {
        if (!CopyBc.checkParams(data)) {
            return Result.success("请输入日期、班次、工序");
        }
        data.setFlag(false);
        String gongxu = data.getGongxu();
        String org = data.getOrg();
        String cj = data.getCj();
        String bc = data.getBc();
        LocalDate time = data.getTime();

        // 查询当前轮班管理该班次安排的时间
        SchedulingShift shift = new SchedulingShift();
        shift.setOrg(org);
        shift.setCj(cj);
        shift.setBc(bc);
        shift.setStartTime(LocalDateTime.of(time, LocalTime.of(0, 0, 0)));
        // 前纺+细纱
        if (!"络筒".equals(gongxu) && WeekEnum.Tuesday.getVal().equals(String.valueOf(time.getDayOfWeek()))) {
            data.setFlag(true);
        }

        List<String> gxs = new ArrayList<>();
        // 前纺处理
        if ("前纺".equals(gongxu)) {
            gxs = Arrays.stream(GXEnum.values()).map(GXEnum::getVal).filter(item -> !item.equals("细纱") && !item.equals("络筒")).collect(Collectors.toList());
        } else {
            gxs.add(gongxu);
        }
        for (String gx : gxs) {
            shift.setGongxu(gx);
            data.setGongxu(gx);
            // 轮班中的开始和结束时间
            Map<String, List<LocalDateTime>> shiftStartAndEndTime = getShiftStartAndEndTime(shift);
            if (shiftStartAndEndTime == null) {
                return Result.error("请前往轮班管理中安排" + gx + "今日排班");
            }
            List<LocalDateTime> startTimeList = shiftStartAndEndTime.get("startTimeList");
            List<LocalDateTime> endTimeList = shiftStartAndEndTime.get("endTimeList");
            QueryWrapper<Scheduling> wrapper = new QueryWrapper<>();
            wrapper.eq("bc", bc);
            wrapper.eq("cj", cj);
            wrapper.eq("current_gongxu", gx);
            wrapper.apply(String.format("DATEDIFF(start_time,'%s')=0", time));
            schedulingMapper.delete(wrapper);
            for (int i = 0; i < startTimeList.size(); i++) {
                data.setStartTime(startTimeList.get(i));
                data.setEndTime(endTimeList.get(i));
                mesContainerMapper.insertScheduleYesterday(data);
            }

            if ("络筒".equals(gx)) {
                QueryWrapper<SpindleNumberMapping> spindleNumberMappingQueryWrapper = new QueryWrapper<>();
                spindleNumberMappingQueryWrapper.eq("cj", cj);
                spindleNumberMappingQueryWrapper.eq("bc", bc);
                spindleNumberMappingQueryWrapper.apply(String.format("DATEDIFF(time,'%s')=0", time));
                spindleNumberMapper.delete(spindleNumberMappingQueryWrapper);
                mesContainerMapper.insertScheduleYesterdayLtDs(data);
            }
        }

        return Result.success("复制成功");
    }

    /**
     * 获取机台选择状态
     */
    public Result getDevSnSelectedStatus(DevSnSelectedStatusReq params) {
        if (!DevSnSelectedStatusReq.checkParams(params)) {
            return Result.error("请输入：组织、车间、工序、设备号、时间、班次、工种、工号、品种");
        }
        String gongxu = params.getGongxu();
        List<String> dicBhs = DevSnAreaEnum.getDevSnAreaEnumDicBhs(gongxu);
        params.setOrg("恒源");
        List<Map> devSnSelectedStatus = schedulingMapper.getDevSnSelectedStatus(params);
        return Result.success(devSnSelectedStatus);
    }

    /**
     * 修改人员排班
     */
    public Result modifyPersonnelClasses(SchedulingShow data) {
        if (data.getCurrent_work_type() == null || StringUtils.isEmpty(data.getCurrent_work_type()) || data.getCj() == null || StringUtils.isEmpty(data.getCj()) || data.getGongxu() == null || StringUtils.isEmpty(data.getGongxu()) || data.getGh() == null || StringUtils.isEmpty(data.getGh()) || data.getBc() == null || StringUtils.isEmpty(data.getBc()) || data.getTime() == null) {
            return Result.error("更新操作必要条件：工号、日期、班次,工种，车间，工序");
        }
        Scheduling s = schedulingMapper.selectById(data.getId());
        LocalDateTime startTime = s.getStart_time();
        LocalDateTime endTime = s.getEnd_time();
        LocalDate time = data.getTime();
        QueryWrapper<Scheduling> queryWrapper = new QueryWrapper<>();
        // 更新员工机台号
        List<String> checkedDev = data.getCheckedDev();
        if (checkedDev != null) {
            /* 查询日计划中该类机台所属品种的机台范围 */
            QueryWrapper<MesNewscjhPojo> mesWrapper = new QueryWrapper<>();
            mesWrapper.clear();
            mesWrapper.apply(String.format("DATEDIFF(time,'%s')=0", data.getTime()));
            mesWrapper.eq("cj", data.getCj());
            mesWrapper.eq("gongxu", data.getGongxu());
            mesWrapper.eq("pz", data.getPz());
            mesWrapper.groupBy("devSn");
            List<MesNewscjhPojo> mesNewscjhPojoList = productionPlanManagementMapper.selectList(mesWrapper);
            List<String> pzDevSnArea = mesNewscjhPojoList.stream().map(MesNewscjhPojo::getDevSn).collect(Collectors.toList());
            // 无机台人员情况
            pzDevSnArea.add("");
            /* 查询旧机台范围 */
            queryWrapper.clear();
            queryWrapper.select("devSn");
            queryWrapper.eq("gh", data.getGh());
            queryWrapper.apply(String.format("DATEDIFF(start_time,'%s')=0", data.getTime()));
            queryWrapper.eq("bc", data.getBc());
            // 避免周一两个甲班
            queryWrapper.gt("end_time", startTime);
            queryWrapper.lt("start_time", endTime);
            queryWrapper.eq("cj", data.getCj());
            queryWrapper.eq("current_gongxu", data.getGongxu());
            queryWrapper.eq("current_work_type", data.getCurrent_work_type());
            queryWrapper.in("devSn", pzDevSnArea);
            queryWrapper.groupBy("devSn");
            List<Scheduling> list = schedulingMapper.selectList(queryWrapper);
            // 旧机台范围
            List<String> devSnAreaOld = list.stream().map(Scheduling::getDevSn).collect(Collectors.toList());
            // 筛选新增机台
            List<String> addDevSnList = checkedDev.stream().filter(item -> !devSnAreaOld.contains(item)).collect(Collectors.toList());
            // 筛选删除机台
            List<String> delDevSnList = devSnAreaOld.stream().filter(item -> !checkedDev.contains(item)).collect(Collectors.toList());
            logger.info("存放新增机台---{}", addDevSnList.toString());
            logger.info("存放删除机台---{}", delDevSnList.toString());
            if (addDevSnList.size() > 0 || delDevSnList.size() > 0) {
                // 查询插入模板
                queryWrapper.clear();
                queryWrapper.eq("gh", data.getGh());
                queryWrapper.apply(String.format("DATEDIFF(start_time,'%s')=0", data.getTime()));
                queryWrapper.eq("bc", data.getBc());
                queryWrapper.eq("cj", data.getCj());
                queryWrapper.eq("current_gongxu", data.getGongxu());
                queryWrapper.eq("current_work_type", data.getCurrent_work_type());
                queryWrapper.gt("end_time", startTime);
                queryWrapper.lt("start_time", endTime);
                queryWrapper.last("limit 1");
                Scheduling temple = schedulingMapper.selectOne(queryWrapper);
                // 当小队中存在落纱队员时，落纱队长不允许新增或减少机台
                if ("落纱队长".equals(data.getCurrent_work_type())) {
                    queryWrapper.clear();
                    queryWrapper.eq("cj", data.getCj());
                    queryWrapper.eq("current_gongxu", data.getGongxu());
                    queryWrapper.apply(String.format("DATEDIFF(start_time,'%s')=0", data.getTime()));
                    queryWrapper.eq("bc", data.getBc());
                    queryWrapper.eq("current_dh", temple.getCurrent_dh());
                    queryWrapper.eq("current_work_type", "落纱队员");
                    queryWrapper.gt("end_time", startTime);
                    queryWrapper.lt("start_time", endTime);
                    List<Scheduling> schedulingLsDy = schedulingMapper.selectList(queryWrapper);
                    if (schedulingLsDy.size() > 0) {
                        return Result.error("【" + temple.getCurrent_dh() + "】中存在落纱队员，落纱队长机台号与队员机台保持一直，不允许单独新增或减少机台");
                    }
                }
                if (addDevSnList.size() > 0) {
                    // 对落纱队员新增机台
                    if ("落纱队员".equals(data.getCurrent_work_type())) {
                        queryWrapper.clear();
                        queryWrapper.eq("cj", data.getCj());
                        queryWrapper.eq("current_gongxu", data.getGongxu());
                        queryWrapper.apply(String.format("DATEDIFF(start_time,'%s')=0", data.getTime()));
                        queryWrapper.eq("bc", data.getBc());
                        queryWrapper.eq("current_dh", temple.getCurrent_dh());
                        queryWrapper.eq("current_work_type", "落纱队长");
                        queryWrapper.gt("end_time", startTime);
                        queryWrapper.lt("start_time", endTime);
                        queryWrapper.groupBy("gh");
                        List<Scheduling> schedulingLsDzList = schedulingMapper.selectList(queryWrapper);
                        for (String devSn : addDevSnList) {
                            for (Scheduling schedulingLsDz : schedulingLsDzList) {
                                schedulingLsDz.setDevSn(devSn);
                                // 落纱队长也新增机台
                                schedulingMapper.insert(schedulingLsDz);
                            }
                        }
                    }
                    // 插入
                    for (String devSn : addDevSnList) {
                        temple.setDevSn(devSn);
                        temple.setShare(1.0);
                        schedulingMapper.insert(temple);
                    }
                }
                if (delDevSnList.size() > 0) {
                    // 对落纱队员减少机台
                    if ("落纱队员".equals(data.getCurrent_work_type())) {
                        queryWrapper.clear();
                        queryWrapper.eq("cj", data.getCj());
                        queryWrapper.eq("current_gongxu", data.getGongxu());
                        queryWrapper.apply(String.format("DATEDIFF(start_time,'%s')=0", data.getTime()));
                        queryWrapper.eq("bc", data.getBc());
                        queryWrapper.eq("current_dh", temple.getCurrent_dh());
                        queryWrapper.eq("current_work_type", "落纱队长");
                        queryWrapper.gt("end_time", startTime);
                        queryWrapper.lt("start_time", endTime);
                        queryWrapper.groupBy("gh");
                        List<Scheduling> schedulingLsDzList = schedulingMapper.selectList(queryWrapper);
                        queryWrapper.clear();
                        queryWrapper.eq("cj", data.getCj());
                        queryWrapper.eq("current_gongxu", data.getGongxu());
                        queryWrapper.apply(String.format("DATEDIFF(start_time,'%s')=0", data.getTime()));
                        queryWrapper.eq("bc", data.getBc());
                        queryWrapper.gt("end_time", startTime);
                        queryWrapper.lt("start_time", endTime);
                        queryWrapper.in("devSn", delDevSnList);
                        queryWrapper.eq("current_work_type", "落纱队长");
                        for (Scheduling schedulingLsDz : schedulingLsDzList) {
                            // 落纱队长也删除机台
                            queryWrapper.eq("gh", schedulingLsDz.getGh());
                            schedulingMapper.delete(queryWrapper);
                        }
                    }
                    // 删除
                    queryWrapper.clear();
                    queryWrapper.eq("gh", data.getGh());
                    queryWrapper.apply(String.format("DATEDIFF(start_time,'%s')=0", data.getTime()));
                    queryWrapper.eq("bc", data.getBc());
                    queryWrapper.eq("cj", data.getCj());
                    queryWrapper.eq("current_gongxu", data.getGongxu());
                    queryWrapper.gt("end_time", startTime);
                    queryWrapper.lt("start_time", endTime);
                    queryWrapper.eq("current_work_type", data.getCurrent_work_type());
                    if (delDevSnList.size() > 0) {
                        queryWrapper.in("devSn", delDevSnList);
                    }
                    schedulingMapper.delete(queryWrapper);
                }
            }
        } else {
            /**
             *  依据：工号、日期、班次
             *  更改：工种、开始时间、结束时间、考勤状态、备注
             */
            queryWrapper.clear();
            queryWrapper.eq("gh", data.getGh());
            queryWrapper.apply(String.format("DATEDIFF(start_time,'%s')=0", data.getTime()));
            queryWrapper.eq("bc", data.getBc());
            queryWrapper.eq("cj", data.getCj());
            queryWrapper.eq("current_gongxu", data.getGongxu());
            queryWrapper.gt("end_time", startTime);
            queryWrapper.lt("start_time", endTime);
            Scheduling u_scheduling = new Scheduling();
            if (!StringUtils.isEmpty(data.getCurrent_work_type())) {
                String current_work_type = data.getCurrent_work_type();
                if (current_work_type.contains("落纱")) {
                    u_scheduling.setCurrent_dh("1队");
                }
                u_scheduling.setCurrent_work_type(current_work_type);
            }
            if (data.getStart_time() != null) {
                u_scheduling.setStart_time(data.getStart_time());
            }
            if (data.getEnd_time() != null) {
                u_scheduling.setEnd_time(data.getEnd_time());
            }
            if (!StringUtils.isEmpty(data.getStatus())) {
                u_scheduling.setStatus(data.getStatus());
            }
            if (data.getRemarks() != null) {
                u_scheduling.setRemarks(data.getRemarks());
            }
            if (!StringUtils.isEmpty(data.getCurrent_dh()) && common.judgeEnumIsExist(data.getCurrent_dh())) {
                u_scheduling.setCurrent_dh(data.getCurrent_dh());
            }
            // 查询新增落纱队长模板
            queryWrapper.clear();
            queryWrapper.eq("cj", data.getCj());
            queryWrapper.eq("current_gongxu", data.getGongxu());
            queryWrapper.eq("bc", data.getBc());
            queryWrapper.apply(String.format("DATEDIFF(start_time,'%s')=0", time));
            queryWrapper.eq("gh", data.getGh());
            queryWrapper.gt("end_time", startTime);
            queryWrapper.lt("start_time", endTime);
            queryWrapper.last("limit 1");
            Scheduling schedulingLsTem = schedulingMapper.selectOne(queryWrapper);
            /* 查询该队伍中的落纱队员 */
            queryWrapper.clear();
            queryWrapper.eq("cj", data.getCj());
            queryWrapper.gt("end_time", startTime);
            queryWrapper.lt("start_time", endTime);
            queryWrapper.eq("current_gongxu", data.getGongxu());
            queryWrapper.eq("bc", data.getBc());
            queryWrapper.apply(String.format("DATEDIFF(start_time,'%s')=0", time));
            queryWrapper.eq("current_work_type", "落纱队员");
            queryWrapper.ne("gh", data.getGh());
            queryWrapper.eq("current_dh", data.getCurrent_dh());
            queryWrapper.groupBy("devSn");
            queryWrapper.orderByAsc("devSn+0");
            List<Scheduling> devSnListLs = schedulingMapper.selectList(queryWrapper);
            // 落纱队长特殊处理-【其他工种转为落纱队长】
            if (devSnListLs.size() > 0 && !"落纱队长".equals(schedulingLsTem.getCurrent_work_type()) && "落纱队长".equals(data.getCurrent_work_type())) {
                // 存在落纱队员 删除该落纱队长原先记录
                queryWrapper.clear();
                queryWrapper.eq("cj", data.getCj());
                queryWrapper.gt("end_time", startTime);
                queryWrapper.lt("start_time", endTime);
                queryWrapper.eq("current_gongxu", data.getGongxu());
                queryWrapper.eq("bc", data.getBc());
                queryWrapper.apply(String.format("DATEDIFF(start_time,'%s')=0", time));
                queryWrapper.eq("gh", data.getGh());
                queryWrapper.eq("current_dh", data.getCurrent_dh());
                schedulingMapper.delete(queryWrapper);
                for (Scheduling schedulingLs : devSnListLs) {
                    schedulingLsTem.setDevSn(schedulingLs.getDevSn());
                    schedulingLsTem.setCurrent_dh(data.getCurrent_dh());
                    schedulingLsTem.setCurrent_work_type("落纱队长");
                    schedulingLsTem.setUpdate_time(LocalDateTime.now());
                    // 新增落纱队长人员排班
                    schedulingMapper.insert(schedulingLsTem);
                }
            } else {
                queryWrapper.clear();
                queryWrapper.eq("gh", data.getGh());
                queryWrapper.gt("end_time", startTime);
                queryWrapper.lt("start_time", endTime);
                queryWrapper.apply(String.format("DATEDIFF(start_time,'%s')=0", data.getTime()));
                queryWrapper.eq("bc", data.getBc());
                queryWrapper.eq("cj", data.getCj());
                queryWrapper.eq("current_gongxu", data.getGongxu());
                schedulingMapper.update(u_scheduling, queryWrapper);

                String preDh = schedulingLsTem.getCurrent_dh();
                String curDh = data.getCurrent_dh();

                // 【其他小队切换到本小队】
                if (preDh != null && !preDh.equals(curDh)) {
                    // 之前小队落纱队员
                    queryWrapper.clear();
                    queryWrapper.eq("cj", data.getCj());
                    queryWrapper.gt("end_time", startTime);
                    queryWrapper.lt("start_time", endTime);
                    queryWrapper.eq("current_gongxu", data.getGongxu());
                    queryWrapper.eq("bc", data.getBc());
                    queryWrapper.apply(String.format("DATEDIFF(start_time,'%s')=0", time));
                    queryWrapper.eq("current_work_type", "落纱队员");
                    queryWrapper.ne("devSn", "");
                    queryWrapper.eq("current_dh", preDh);
                    queryWrapper.groupBy("devSn");
                    queryWrapper.orderByAsc("devSn+0");
                    List<Scheduling> preLsDy = schedulingMapper.selectList(queryWrapper);
                    // 当前小队落纱队员
                    queryWrapper.clear();
                    queryWrapper.eq("cj", data.getCj());
                    queryWrapper.gt("end_time", startTime);
                    queryWrapper.lt("start_time", endTime);
                    queryWrapper.eq("current_gongxu", data.getGongxu());
                    queryWrapper.eq("bc", data.getBc());
                    queryWrapper.apply(String.format("DATEDIFF(start_time,'%s')=0", time));
                    queryWrapper.eq("current_work_type", "落纱队员");
                    queryWrapper.ne("devSn", "");
                    queryWrapper.eq("current_dh", curDh);
                    queryWrapper.groupBy("devSn");
                    queryWrapper.orderByAsc("devSn+0");
                    List<Scheduling> curLsDy = schedulingMapper.selectList(queryWrapper);

                    // 之前小队落纱队长
                    queryWrapper.clear();
                    queryWrapper.eq("cj", data.getCj());
                    queryWrapper.gt("end_time", startTime);
                    queryWrapper.lt("start_time", endTime);
                    queryWrapper.eq("current_gongxu", data.getGongxu());
                    queryWrapper.eq("bc", data.getBc());
                    queryWrapper.apply(String.format("DATEDIFF(start_time,'%s')=0", time));
                    queryWrapper.eq("current_work_type", "落纱队长");
                    queryWrapper.eq("current_dh", preDh);
                    queryWrapper.groupBy("gh");
                    List<Scheduling> preLsDz = schedulingMapper.selectList(queryWrapper);
                    // 当前小队落纱队长
                    queryWrapper.clear();
                    queryWrapper.eq("cj", data.getCj());
                    queryWrapper.gt("end_time", startTime);
                    queryWrapper.lt("start_time", endTime);
                    queryWrapper.eq("current_gongxu", data.getGongxu());
                    queryWrapper.eq("bc", data.getBc());
                    queryWrapper.apply(String.format("DATEDIFF(start_time,'%s')=0", time));
                    queryWrapper.eq("current_work_type", "落纱队长");
                    queryWrapper.eq("current_dh", curDh);
                    queryWrapper.groupBy("gh");
                    List<Scheduling> curLsDz = schedulingMapper.selectList(queryWrapper);

                    if ("落纱队长".equals(data.getCurrent_work_type())) {
                        if (curLsDy.size() > 0) {
                            queryWrapper.clear();
                            queryWrapper.eq("cj", data.getCj());
                            queryWrapper.gt("end_time", startTime);
                            queryWrapper.lt("start_time", endTime);
                            queryWrapper.eq("current_gongxu", data.getGongxu());
                            queryWrapper.eq("bc", data.getBc());
                            queryWrapper.apply(String.format("DATEDIFF(start_time,'%s')=0", time));
                            queryWrapper.eq("gh", data.getGh());
                            queryWrapper.eq("current_work_type", data.getCurrent_work_type());
                            queryWrapper.eq("current_dh", curDh);
                            schedulingMapper.delete(queryWrapper);

                            for (Scheduling pre : curLsDy) {
                                schedulingLsTem.setDevSn(pre.getDevSn());
                                schedulingLsTem.setCurrent_dh(curDh);
                                schedulingLsTem.setCurrent_work_type("落纱队长");
                                schedulingLsTem.setUpdate_time(LocalDateTime.now());
                                // 新增落纱队长人员排班
                                schedulingMapper.insert(schedulingLsTem);
                            }
                        }
                    }

                    if ("落纱队员".equals(data.getCurrent_work_type())) {
                        if (curLsDz.size() > 0) {
                            // 删除当前小队落纱队长
                            for (Scheduling item : curLsDz) {
                                queryWrapper.clear();
                                queryWrapper.gt("end_time", startTime);
                                queryWrapper.lt("start_time", endTime);
                                queryWrapper.eq("cj", item.getCj());
                                queryWrapper.eq("current_gongxu", item.getCurrent_gongxu());
                                queryWrapper.eq("bc", item.getBc());
                                queryWrapper.apply(String.format("DATEDIFF(start_time,'%s')=0", time));
                                queryWrapper.eq("gh", item.getGh());
                                queryWrapper.eq("current_work_type", item.getCurrent_work_type());
                                queryWrapper.eq("current_dh", curDh);
                                schedulingMapper.delete(queryWrapper);
                                for (Scheduling pre : curLsDy) {
                                    item.setDevSn(pre.getDevSn());
                                    item.setUpdate_time(LocalDateTime.now());
                                    // 新增落纱队长人员排班
                                    schedulingMapper.insert(item);
                                }
                            }
                        }
                        if (preLsDz.size() > 0) {
                            // 删除pre前小队落纱队长
                            for (Scheduling item : preLsDz) {
                                queryWrapper.clear();
                                queryWrapper.gt("end_time", startTime);
                                queryWrapper.lt("start_time", endTime);
                                queryWrapper.eq("cj", item.getCj());
                                queryWrapper.eq("current_gongxu", item.getCurrent_gongxu());
                                queryWrapper.eq("bc", item.getBc());
                                queryWrapper.apply(String.format("DATEDIFF(start_time,'%s')=0", time));
                                queryWrapper.eq("gh", item.getGh());
                                queryWrapper.eq("current_work_type", item.getCurrent_work_type());
                                queryWrapper.eq("current_dh", preDh);
                                schedulingMapper.delete(queryWrapper);
                                for (Scheduling pre : preLsDy) {
                                    item.setDevSn(pre.getDevSn());
                                    item.setUpdate_time(LocalDateTime.now());
                                    // 新增落纱队长人员排班
                                    schedulingMapper.insert(item);
                                }
                            }
                        }
                    }
                }
            }
        }
        return Result.success("更新成功");
    }

    /**
     * 查询络筒锭数选择状态
     */
    public Result getDsSelectedStatus(DsSelectedStatusReq data) {
        List<Map> dsSelectedStatus = schedulingMapper.getDsSelectedStatus(data);
        return Result.success(dsSelectedStatus);
    }

    // 修改络筒锭数
    public Result modifyDailyPlanLtDs(Id2 data) {
        String uuid = UUID.randomUUID().toString().replace("-", "").toLowerCase();
        Integer id = data.getId();
        String pz = data.getPz();
        String idLt = data.getIdLt();
        List<String> dsArea = data.getDsArea();
        if (pz == null) {
            return Result.error("请先选择品种");
        }
        Scheduling spindleTem = schedulingMapper.selectById(id);
        String gongxu = spindleTem.getCurrent_gongxu();
        String cj = spindleTem.getCj();
        String bc = spindleTem.getBc();
        String devSn = spindleTem.getDevSn();
        String gh = spindleTem.getGh();
        LocalDateTime time = spindleTem.getStart_time();

        QueryWrapper<SpindleNumberMapping> wrapper = new QueryWrapper<>();
        // 校验同一gh、机台不能有相同品种
        wrapper.clear();
        wrapper.eq("gongxu", "络筒");
        wrapper.eq("cj", cj);
        wrapper.eq("devSn", devSn);
        wrapper.eq("pz", pz);
        wrapper.apply(String.format("DATEDIFF(time,'%s')=0", time));
        wrapper.eq("bc", bc);
        wrapper.eq("gh", gh);
        if (!StringUtils.isEmpty(idLt)) {
            wrapper.ne("idLt", idLt);
        }

        List<SpindleNumberMapping> flag = spindleNumberMapper.selectList(wrapper);
        if (flag.size() > 0) {
            return Result.error("该人员" + devSn + "号机台已有该品种，请勿重复添加");
        }

        SpindleNumberMapping spindleNumberMapping = new SpindleNumberMapping();
        spindleNumberMapping.setGongxu(gongxu);
        spindleNumberMapping.setCj(cj);
        spindleNumberMapping.setDevSn(devSn);
        spindleNumberMapping.setTime(time.toLocalDate());
        spindleNumberMapping.setBc(bc);
        spindleNumberMapping.setGh(gh);
        spindleNumberMapping.setPz(pz);
        if (idLt != null) {
            wrapper.clear();
            wrapper.eq("idLt", idLt);
            wrapper.apply(String.format("DATEDIFF(time,'%s')=0", time));
            spindleNumberMapper.delete(wrapper);
            spindleNumberMapping.setIdLt(idLt);
        } else {
            QueryWrapper<Scheduling> schedulingQueryWrapper = new QueryWrapper<>();
            schedulingQueryWrapper.clear();
            schedulingQueryWrapper.eq("id", id);
            Scheduling scheduling = new Scheduling();
            scheduling.setIdLt(uuid);
            // 根据排班id更新排班idLt
            schedulingMapper.update(scheduling, schedulingQueryWrapper);
            spindleNumberMapping.setIdLt(uuid);
        }
        for (String ds : dsArea) {
            spindleNumberMapping.setDs(ds);
            spindleNumberMapper.insert(spindleNumberMapping);
        }
        return Result.success("修改成功");
    }

    /**
     * 修改人员排班络筒
     */
    public Result modifyPersonnelClassesLt(ModifyScheduling data) {
        if (data.getDevSn() == null || StringUtils.isEmpty(data.getGh()) || StringUtils.isEmpty(data.getBc()) || data.getTime() == null) {
            return Result.error("络筒更新操作必要条件：机台号、工号、日期、班次");
        }
        QueryWrapper<Scheduling> queryWrapper = new QueryWrapper<>();
        // 更新员工锭数
        List<String> check = data.getCheck();
        if (check != null && check.size() > 0) {
            // 另外的接口
        } else {
            /**
             *  依据：工号、日期、班次
             *  更改：工种、开始时间、结束时间、考勤状态、备注
             */
            queryWrapper.clear();
            queryWrapper.eq("gh", data.getGh());
            queryWrapper.apply(String.format("DATEDIFF(start_time,'%s')=0", data.getTime()));
            queryWrapper.eq("cj", data.getCj());
            queryWrapper.eq("current_gongxu", "络筒");
            queryWrapper.eq("bc", data.getBc());
            queryWrapper.eq("devSn", data.getDevSn());
            if (!StringUtils.isEmpty(data.getIdLt())) {
                queryWrapper.eq("idLt", data.getIdLt());
            }
            Scheduling u_scheduling = new Scheduling();
            if (!StringUtils.isEmpty(data.getCurrent_work_type()) && data.getCurrent_work_type() != null) {
                u_scheduling.setCurrent_work_type(data.getCurrent_work_type());
            }
            if (data.getStart_time() != null) {
                u_scheduling.setStart_time(data.getStart_time());
            }
            if (data.getEnd_time() != null) {
                u_scheduling.setEnd_time(data.getEnd_time());
            }
            if (!StringUtils.isEmpty(data.getStatus()) && data.getStatus() != null) {
                u_scheduling.setStatus(data.getStatus());
            }
            if (data.getRemarks() != null) {
                u_scheduling.setRemarks(data.getRemarks());
            }
            schedulingMapper.update(u_scheduling, queryWrapper);
        }

        return Result.success("更新成功");
    }

    /**
     * 判断日计划中是否存在该机台范围
     *
     * @param data
     * @return
     */
    public List<String> judgeWhetherTheDailyPlanExistsDev(AddScheduling data) {
        String cj = data.getCj();
        String gongxu = data.getCurrent_gongxu();
        LocalDate time = data.getTime();
        List<String> area = data.getDevSnArea();

        List<String> mesNoExist = new ArrayList<>();
        QueryWrapper<MesNewscjhPojo> mesWrapper = new QueryWrapper<>();
        // 若机台范围不为空判断日计划中是否存在该机台
        for (String devSn : area) {
            mesWrapper.clear();
            mesWrapper.eq("cj", cj);
            mesWrapper.eq("gongxu", gongxu);
            mesWrapper.eq("devSn", devSn);
            mesWrapper.apply(String.format("DATEDIFF(time,'%s')=0", time));
            mesWrapper.last("limit 1");
            MesNewscjhPojo mesNewscjhPojo = productionPlanManagementMapper.selectOne(mesWrapper);
            if (mesNewscjhPojo == null) {
                mesNoExist.add(devSn);
            }
        }
        return mesNoExist;
    }

    /**
     * 获得该班次开始结束时间
     */
    public Map<String, List<LocalDateTime>> getShiftStartAndEndTime(SchedulingShift params) {
        String org = params.getOrg();
        String cj = params.getCj();
        String gongxu = params.getGongxu();
        String bc = params.getBc();
        LocalDateTime startTime = params.getStartTime();
        QueryWrapper<SchedulingShift> wrapper = new QueryWrapper<>();
        wrapper.eq("org", org)
                .eq("cj", cj)
                .eq("gongxu", gongxu)
                .eq("bc", bc)
                .apply(String.format("DATEDIFF(startTime,'%s')=0", startTime));
        List<SchedulingShift> schedulingShifts = schedulingShiftMapper.selectList(wrapper);
        if (schedulingShifts.size() == 0) {
            return null;
        }
        List<LocalDateTime> startTimeList = schedulingShifts.stream().map(SchedulingShift::getStartTime).collect(Collectors.toList());
        List<LocalDateTime> endTimeList = schedulingShifts.stream().map(SchedulingShift::getEndTime).collect(Collectors.toList());
        Map<String, List<LocalDateTime>> res = new HashMap<>();
        res.put("startTimeList", startTimeList);
        res.put("endTimeList", endTimeList);
        return res;
    }

    /**
     * 新增人员排班
     */
    public Result addPersonnelClasses(AddScheduling data) throws Exception {
        if (data.getGhList().size() == 0 || data.getGhList() == null || StringUtils.isEmpty(data.getBc()) || StringUtils.isEmpty(data.getCj()) || StringUtils.isEmpty(data.getCurrent_gongxu())) {
            return Result.error("新增人员排班必要条件：工号数组、工序、班次、车间、工种");
        }

        List<String> area = data.getDevSnArea();
        String gongxu = data.getCurrent_gongxu();
        LocalDate time = data.getTime();
        String cj = data.getCj();
        List<String> ghList = data.getGhList();
        List<String> devSnArea = data.getDevSnArea();
        String bc = data.getBc();
        String org = data.getOrg();

        SchedulingShift shift = new SchedulingShift();
        shift.setOrg(org);
        shift.setCj(cj);
        shift.setGongxu(gongxu);
        shift.setBc(bc);
        shift.setStartTime(LocalDateTime.of(time, LocalTime.of(0, 0, 0)));
        // 轮班中的开始和结束时间
        Map<String, List<LocalDateTime>> shiftStartAndEndTime = getShiftStartAndEndTime(shift);
        if (shiftStartAndEndTime == null) {
            return Result.error("请前往轮班管理中安排今日排班");
        }
        List<LocalDateTime> startTimeList = shiftStartAndEndTime.get("startTimeList");
        List<LocalDateTime> endTimeList = shiftStartAndEndTime.get("endTimeList");

        // 若机台范围不为空判断日计划中是否存在该机台
        List<String> judgeWhetherTheDailyPlanExistsDevBoolean = judgeWhetherTheDailyPlanExistsDev(data);
        if (judgeWhetherTheDailyPlanExistsDevBoolean.size() > 0) {
            return Result.error("日计划中不存在车台：" + judgeWhetherTheDailyPlanExistsDevBoolean + "、请先添加日计划");
        }

        QueryWrapper<MesNewscjhPojo> mesWrapper = new QueryWrapper<>();
        // 个人信息
        QueryWrapper<SchedulingPersonnel> schedulingPersonnelQueryWrapper = new QueryWrapper<>();
        // 工序对应工种字典表
        QueryWrapper<FzyDictionaryDataList> fzyDictionaryDataListQueryWrapper = new QueryWrapper<>();
        QueryWrapper<Scheduling> queryWrapper = new QueryWrapper<>();
        Scheduling scheduling = new Scheduling();
        scheduling.setCj(data.getCj());
        scheduling.setBc(data.getBc());
        scheduling.setCurrent_gongxu(data.getCurrent_gongxu());
        scheduling.setShare(1.0);
        scheduling.setCurrent_dh("1队");
        scheduling.setUpdate_time(LocalDateTime.now());

        ArrayList<String> exists = new ArrayList<>();
        for (int t = 0; t < startTimeList.size(); t++) {
            // 根据轮班管理设置开始结束时间
            scheduling.setStart_time(startTimeList.get(t));
            scheduling.setEnd_time(endTimeList.get(t));
            for (String gh : ghList) {
                /* 在岗状态设置 */
                schedulingPersonnelQueryWrapper.clear();
                schedulingPersonnelQueryWrapper.eq("gh", gh);
                schedulingPersonnelQueryWrapper.last("limit 1");
                SchedulingPersonnel personnelInfo = schedulingPersonnelMapper.selectOne(schedulingPersonnelQueryWrapper);
                //工序、班次、车间
                if (personnelInfo.getCj().equals(data.getCj()) && personnelInfo.getGongxu().equals(data.getCurrent_gongxu()) && personnelInfo.getBc().equals(data.getBc())) {
                    scheduling.setStatus("在岗");
                } else {
                    scheduling.setStatus("借调");
                }

                /* 工种设置，若符合工序对应的工种条件则直接添加，否则默认挡车工 */
                fzyDictionaryDataListQueryWrapper.clear();
                fzyDictionaryDataListQueryWrapper.select("key_name");
                fzyDictionaryDataListQueryWrapper.eq("key_value", data.getCurrent_gongxu());
                fzyDictionaryDataListQueryWrapper.last("limit 1");
                FzyDictionaryDataList keyNameList = dictionaryDataListMapper.selectOne(fzyDictionaryDataListQueryWrapper);
                // 获取对应工序键名
                String key_name = keyNameList.getKey_name();
                // 查询对应工种
                fzyDictionaryDataListQueryWrapper.clear();
                fzyDictionaryDataListQueryWrapper.select("key_value");
                fzyDictionaryDataListQueryWrapper.eq("belong", key_name);
                List<FzyDictionaryDataList> workTypeList = dictionaryDataListMapper.selectList(fzyDictionaryDataListQueryWrapper);
                boolean workTypeIsOk = false;
                for (FzyDictionaryDataList item : workTypeList) {
                    if (item.getKey_value().equals(personnelInfo.getWorkType())) {
                        workTypeIsOk = true;
                        break;
                    }
                }
                if (workTypeIsOk) {
                    scheduling.setCurrent_work_type(personnelInfo.getWorkType());
                } else {
                    scheduling.setCurrent_work_type("挡车工");
                }

                /* 查询是否已经存在该工种该人员排班 */
                queryWrapper.clear();
                queryWrapper.apply(String.format("DATEDIFF(start_time,'%s')=0", time));
                queryWrapper.eq("bc", data.getBc());
                queryWrapper.eq("cj", data.getCj());
                queryWrapper.eq("current_gongxu", data.getCurrent_gongxu());
                queryWrapper.eq("current_work_type", scheduling.getCurrent_work_type());
                queryWrapper.eq("gh", gh);
                // 避免周一两个甲班
                queryWrapper.gt("end_time", startTimeList.get(t));
                queryWrapper.lt("start_time", endTimeList.get(t));
                scheduling.setGh(gh);
                List<Scheduling> judgeBeforeInsert = new ArrayList<>();
                // 络筒不判断，可重复添加
                if (!"络筒".equals(data.getCurrent_gongxu())) {
                    judgeBeforeInsert = schedulingMapper.selectList(queryWrapper);
                }
                if (judgeBeforeInsert.size() > 0) {
                    exists.add(gh);
                } else if (devSnArea.size() == 0) {
                    /* 插入无机台人员排班 */
                    insertNoEquipmentOperator(scheduling);
                } else {
                    if ("抓棉".equals(gongxu) || "开棉".equals(gongxu) || "多仓".equals(gongxu)) {
                        System.out.println("==============【抓棉：1|2；开棉1，2|3，4；多仓1，2|3，4】===================");
                        // 【抓棉：1|2；开棉1，2|3，4；多仓1，2|3，4】
                        ArrayList<String> devQh1 = new ArrayList<>();
                        devQh1.add("1");
                        devQh1.add("2");
                        ArrayList<String> devQh2 = new ArrayList<>();
                        devQh2.add("3");
                        devQh2.add("4");
                        if (("抓棉".equals(gongxu) && devSnArea.contains("1")) || ("开棉".equals(gongxu) && !Collections.disjoint(devSnArea, devQh1)) || ("多仓".equals(gongxu) && !Collections.disjoint(devSnArea, devQh1))) {
                            scheduling.setCurrent_gongxu("抓棉");
                            scheduling.setDevSn("1");
                            schedulingMapper.insert(scheduling);
                            for (String devSn : devQh1) {
                                scheduling.setCurrent_gongxu("开棉");
                                scheduling.setDevSn(devSn);
                                schedulingMapper.insert(scheduling);
                                scheduling.setCurrent_gongxu("多仓");
                                scheduling.setDevSn(devSn);
                                schedulingMapper.insert(scheduling);
                            }
                        }
                        if (("抓棉".equals(gongxu) && devSnArea.contains("2")) || ("开棉".equals(gongxu) && !Collections.disjoint(devSnArea, devQh2)) || ("多仓".equals(gongxu) && !Collections.disjoint(devSnArea, devQh2))) {
                            scheduling.setCurrent_gongxu("抓棉");
                            scheduling.setDevSn("2");
                            schedulingMapper.insert(scheduling);
                            for (String devSn : devQh2) {
                                scheduling.setCurrent_gongxu("开棉");
                                scheduling.setDevSn(devSn);
                                schedulingMapper.insert(scheduling);
                                scheduling.setCurrent_gongxu("多仓");
                                scheduling.setDevSn(devSn);
                                schedulingMapper.insert(scheduling);
                            }
                        }
                    } else {
                        // 新增人员排班
                        for (String devSn : devSnArea) {
                            // 络筒默认锭数1-64锭
                            if ("络筒".equals(data.getCurrent_gongxu())) {
                                String uuid = UUID.randomUUID().toString().replace("-", "").toLowerCase();
                                QueryWrapper<Scheduling> schedulingQueryWrapper = new QueryWrapper<>();
                                schedulingQueryWrapper.eq("devSn", devSn);
                                schedulingQueryWrapper.eq("cj", cj);
                                schedulingQueryWrapper.eq("bc", data.getBc());
                                schedulingQueryWrapper.eq("current_gongxu", "络筒");
                                schedulingQueryWrapper.apply(String.format("DATEDIFF(start_time,'%s')=0", time));
                                List<Scheduling> schedulingLt = schedulingMapper.selectList(schedulingQueryWrapper);
                                mesWrapper.clear();
                                mesWrapper.eq("gongxu", "络筒");
                                mesWrapper.eq("devSn", devSn);
                                mesWrapper.eq("cj", cj);
                                mesWrapper.apply(String.format("DATEDIFF(time,'%s')=0", time));
                                mesWrapper.last("limit 1");
                                MesNewscjhPojo mesNewscjhPojo = productionPlanManagementMapper.selectOne(mesWrapper);
                                // 络筒不存在该机台排班
                                if (schedulingLt.size() == 0) {
                                    scheduling.setIdLt(uuid);
                                    SpindleNumberMapping spindleNumberMapping = new SpindleNumberMapping();
                                    spindleNumberMapping.setGongxu(gongxu);
                                    spindleNumberMapping.setCj(cj);
                                    spindleNumberMapping.setDevSn(devSn);
                                    spindleNumberMapping.setTime(time);
                                    spindleNumberMapping.setBc(data.getBc());
                                    spindleNumberMapping.setGh(gh);
                                    spindleNumberMapping.setIdLt(uuid);
                                    spindleNumberMapping.setPz(mesNewscjhPojo.getPz());
                                    for (int i = 1; i <= 64; i++) {
                                        spindleNumberMapping.setDs(String.valueOf(i));
                                        spindleNumberMapper.insert(spindleNumberMapping);
                                    }
                                }
                            }
                            scheduling.setDevSn(devSn);
                            schedulingMapper.insert(scheduling);
                        }
                    }

                    /* 添加完成后落纱队长、队员特殊处理 */
                    if (scheduling.getCurrent_work_type().contains("落纱")) {
                        // 落纱1队队落纱队员
                        queryWrapper.clear();
                        queryWrapper.eq("cj", data.getCj());
                        queryWrapper.eq("current_gongxu", data.getCurrent_gongxu());
                        queryWrapper.eq("bc", data.getBc());
                        queryWrapper.apply(String.format("DATEDIFF(start_time,'%s')=0", time));
                        queryWrapper.eq("current_work_type", "落纱队员");
                        queryWrapper.ne("devSn", "");
                        queryWrapper.eq("current_dh", "1队");
                        queryWrapper.gt("end_time", startTimeList.get(t));
                        queryWrapper.lt("start_time", endTimeList.get(t));
                        queryWrapper.groupBy("devSn");
                        queryWrapper.orderByAsc("devSn+0");
                        List<Scheduling> curLsDy = schedulingMapper.selectList(queryWrapper);
                        // 落纱1队落纱队长
                        queryWrapper.clear();
                        queryWrapper.eq("cj", data.getCj());
                        queryWrapper.eq("current_gongxu", data.getCurrent_gongxu());
                        queryWrapper.eq("bc", data.getBc());
                        queryWrapper.gt("end_time", startTimeList.get(t));
                        queryWrapper.lt("start_time", endTimeList.get(t));
                        queryWrapper.apply(String.format("DATEDIFF(start_time,'%s')=0", time));
                        queryWrapper.eq("current_work_type", "落纱队长");
                        queryWrapper.eq("current_dh", "1队");
                        queryWrapper.groupBy("gh");
                        List<Scheduling> curLsDz = schedulingMapper.selectList(queryWrapper);
                        if ("落纱队长".equals(scheduling.getCurrent_work_type())) {
                            if (curLsDy.size() > 0) {
                                queryWrapper.clear();
                                queryWrapper.eq("cj", data.getCj());
                                queryWrapper.eq("current_gongxu", data.getCurrent_gongxu());
                                queryWrapper.eq("bc", data.getBc());
                                queryWrapper.apply(String.format("DATEDIFF(start_time,'%s')=0", time));
                                queryWrapper.eq("gh", gh);
                                queryWrapper.gt("end_time", startTimeList.get(t));
                                queryWrapper.lt("start_time", endTimeList.get(t));
                                queryWrapper.eq("current_work_type", "落纱队长");
                                schedulingMapper.delete(queryWrapper);

                                for (Scheduling pre : curLsDy) {
                                    scheduling.setDevSn(pre.getDevSn());
                                    scheduling.setUpdate_time(LocalDateTime.now());
                                    schedulingMapper.insert(scheduling);
                                }
                            }
                        }
                        if ("落纱队员".equals(scheduling.getCurrent_work_type())) {
                            if (curLsDz.size() > 0) {
                                // 删除当前小队落纱队长
                                for (Scheduling item : curLsDz) {
                                    queryWrapper.clear();
                                    queryWrapper.gt("end_time", startTimeList.get(t));
                                    queryWrapper.lt("start_time", endTimeList.get(t));
                                    queryWrapper.eq("cj", item.getCj());
                                    queryWrapper.eq("current_gongxu", item.getCurrent_gongxu());
                                    queryWrapper.eq("bc", item.getBc());
                                    queryWrapper.apply(String.format("DATEDIFF(start_time,'%s')=0", time));
                                    queryWrapper.eq("gh", item.getGh());
                                    queryWrapper.eq("current_work_type", item.getCurrent_work_type());
                                    queryWrapper.eq("current_dh", "1队");
                                    schedulingMapper.delete(queryWrapper);
                                    for (Scheduling pre : curLsDy) {
                                        item.setDevSn(pre.getDevSn());
                                        item.setUpdate_time(LocalDateTime.now());
                                        // 新增落纱队长人员排班
                                        schedulingMapper.insert(item);
                                    }
                                }
                            }
                        }
                    }

                }
            }
        }
        logger.info("{}以上工号当前班次已存在排班计划", exists.toString());
        String tips = "新增成功";
        if (exists.size() > 0) {
            tips = exists.toString() + "以上工号在当前班次" + scheduling.getCurrent_work_type() + "已存在排班计划";
        }
        return Result.success(tips);
    }

    public Result insertNoEquipmentOperator(Scheduling params) {
        params.setDevSn("");
        schedulingMapper.insert(params);
        return Result.success("插入无设备人员成功");
    }

    /**
     * 新增人员信息（单个）
     *
     * @param data
     * @return
     */
    public Result addPersonnel(SchedulingPersonnel data) {
        String msg = data.saveCheck();
        if (!StringUtils.isEmpty(msg)) {
            return Result.error(msg);
        }
        //工号唯一，不能出现重复记录
        QueryWrapper<SchedulingPersonnel> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("gh", data.getGh());
        Integer i = schedulingPersonnelMapper.selectCount(queryWrapper);
        if (i > 0) {
            return Result.error("工号重复");
        }
        int insert = schedulingPersonnelMapper.insert(data);
        return insert > 0 ? Result.success("新增成功") : Result.error("系统异常");
    }

    /**
     * 修改人员信息
     *
     * @param data
     * @return
     */
    public Result modifyPersonnel(SchedulingPersonnel data) {
        String msg = data.updateCheck();
        if (!StringUtils.isEmpty(msg)) {
            return Result.error(msg);
        }
        //工号唯一，不能出现重复记录
        QueryWrapper<SchedulingPersonnel> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("gh", data.getGh());
        List<SchedulingPersonnel> recode = schedulingPersonnelMapper.selectList(queryWrapper);
        if (null == recode) {
            return Result.error("记录不存在");
        }
        int insert = schedulingPersonnelMapper.update(data, queryWrapper);
        return insert > 0 ? Result.success("更新成功") : Result.error("系统异常");
    }

    /**
     * 删除人员信息
     *
     * @param array
     * @return
     */
    public Result deletePersonnel(String[] array) {
        if (null == array || array.length <= 0) {
            return Result.error("参数错误");
        }
        QueryWrapper<SchedulingPersonnel> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("gh", array);
        int i = schedulingPersonnelMapper.delete(queryWrapper);
        return i > 0 ? Result.success("删除成功") : Result.error("系统异常");
    }

    /**
     * 多条件查询人员信息
     *
     * @param data
     * @return
     */
    public Result queryPersonnel(SchedulingPersonnel data, Page<SchedulingPersonnel> page) {
        QueryWrapper<SchedulingPersonnel> queryWrapper = new QueryWrapper<>();
        if (!StringUtils.isEmpty(data.getGh()) && !"null".equals(data.getGh())) {
            queryWrapper.eq("gh", data.getGh());
        }
        if (!StringUtils.isEmpty(data.getBc()) && !"null".equals(data.getBc())) {
            queryWrapper.eq("bc", data.getBc());
        }
        if (!StringUtils.isEmpty(data.getCj()) && !"null".equals(data.getCj())) {
            queryWrapper.eq("cj", data.getCj());
        }
        if (!StringUtils.isEmpty(data.getWorkType()) && !"null".equals(data.getWorkType())) {
            queryWrapper.eq("work_type", data.getWorkType());
        }
        if (!StringUtils.isEmpty(data.getGongxu()) && !"null".equals(data.getGongxu())) {
            queryWrapper.eq("gongxu", data.getGongxu());
        }
        if (!StringUtils.isEmpty(data.getName()) && !"null".equals(data.getName())) {
            queryWrapper.like("name", data.getName());
        }
        if (!StringUtils.isEmpty(data.getOrg()) && !"null".equals(data.getOrg())) {
            queryWrapper.eq("org", data.getOrg());
        }
        if (!StringUtils.isEmpty(data.getGroup()) && !"null".equals(data.getGroup())) {
            queryWrapper.eq("`group`", data.getGroup());
        }
        Page<SchedulingPersonnel> result = schedulingPersonnelMapper.selectPage(page, queryWrapper);
        Map<String, Object> res = new HashMap<>();
        res.put("dataList", result.getRecords());
        res.put("total", result.getTotal());
        return Result.success(result);
    }

    public String getChineseToPinyin(String str) {
        // 中文字符串转换为字符数组
        char[] chars = str.toCharArray();
        // 设置转换格式
        HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
        // 小写
        format.setCaseType(HanyuPinyinCaseType.LOWERCASE);
        // 无声调，WITH_TONE_NUMBER表示用数字表示声调, WITH_TONE_MARK表示用声调符号表示
        format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
        // 特殊拼音ü的的显示格式
        format.setVCharType(HanyuPinyinVCharType.WITH_V);
        StringBuilder result = new StringBuilder();
        try {
            for (char c : chars) {
                // 通过正则判断是否为汉字字符
                if (Character.toString(c).matches("[\\u4E00-\\u9FA5]+")) {
                    String[] s = PinyinHelper.toHanyuPinyinStringArray(c, format);
                    result.append(s[0]);
                } else {
                    result.append(c);
                }
            }
            return result.toString();
        } catch (BadHanyuPinyinOutputFormatCombination e1) {
            e1.printStackTrace();
        }
        return result.toString();
    }


    /**
     * 查询所有工序无对应机台工种
     */
    public Result queryNoTypeOfWorkInModel(NoTypeOfWorkInModel data) {
        String gongxu = data.getGongxu();
        List<Map> result = null;
        //if (gongxu.equals("前纺")){
        //    result = mesContainerMapper.queryNoTypeOfWorkInModelQf(data);
        //}else {
        //   result = mesContainerMapper.queryNoTypeOfWorkInModel(data);
        //}
        return Result.success(result);
    }
}
